<%@ page language="java" pageEncoding="UTF-8"%>
<%@ include file="../../taglib.jsp"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://"
			+ request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<base href="<%=basePath%>" />
<%@ include file="/webmodules/console/css.jsp"%>
<%@ include file="/webmodules/console/js.jsp"%>
</head>
<body>
	<div style="width: 100%; height: 100%; overflow: auto;">
		<form id="myform" method="post" enctype="multipart/form-data">
			<input type="hidden" id="path" name="path" value="${param.path }">
			<input type="hidden" id="filenum" name="filenum" value="1">
			<input type="hidden" id="index" name="index" value="">
			<table id="filesupload" width="100%" border="0">
				<tr index="1">
					<td><input type="file" name="file1" width="100%"/></td>
					<td width="20%"><a href="javascript:void(0);" class="easyui-linkbutton" iconCls="icon-cancel" onclick="remove(this);"></a></td>
				</tr>
			</table>
		</form>
		<table width="100%" border="0" align="center" cellpadding="0" cellspacing="0" class="dialog_button_bar">
			<tbody>
				<tr>
					<td>
						<div align="right">
							<a href="javascript:void(0);" class="easyui-linkbutton" iconCls="icon-add" onclick="add();">增加</a> <a href="javascript:void(0);" class="easyui-linkbutton" iconCls="icon-ok" onclick="save();">确定</a>
							<a href="javascript:void(0);" class="easyui-linkbutton" iconCls="icon-cancel" onclick="top.closeWindow('upload');">关闭</a>
						</div>
					</td>
				</tr>
			</tbody>
		</table>
	</div>
</body>
<script type="text/javascript">
	$(function() {
		$('#myform').form({
			url : 'dragon/modules/file/action/FileHandler/upload.ejw',
			onSubmit : function() {
				return $(this).form('validate');
			},
			success : function(data) {
				try {
					data = eval('(' + data + ')');
				} catch (e) {
					top.showErrorMsg("出错了", data);
					return;
				}
				if (data.MESSAGE_ERROR != undefined && data.MESSAGE_ERROR != '') {
					top.showMsg("错误", data.MESSAGE_ERROR, true, 'error');
				} else if (data.MESSAGE_WARNING != undefined && data.MESSAGE_WARNING != '') {
					top.showMsg("警告", data.MESSAGE_WARNING, true, 'warning');
				} else {
					if (data.MESSAGE_INFO != undefined && data.MESSAGE_INFO != '') {
						top.showMsg("", data.MESSAGE_INFO, false);
					} else {
						top.showMsg("", "文件上传成功！", false);
					}
					top.$('#tabsconetnt').tabs('getSelected').find('iframe')[0].contentWindow.$('#mydatagrid').datagrid('reload');
					top.closeWindow('upload');
				}
			}
		});
	});
	function save() {
		var files = $(":file");
		var index = new Array();
		files.each(function() {
			if ($(this).val().trim().length > 0) {
				index.push($(this).parent().parent().attr("index"));
			}
		});
		if (index.length==0) {
			top.showMsg('错误', '请先选择文件！', true, 'error');
			return;
		}
		$('#index').val(index.join(','));
		$('#myform').submit();
	}
	function add() {
		var i = $('#filenum').val();
		i++;
		$('#filenum').val(i);
		var tr = "<tr index=\""+i+"\">"
				+ "<td><input type=\"file\" name=\"file"+i+"\" width=\"100%\"></td>"
				+ "<td width=\"20%\"><a href=\"javascript:void(0);\" class=\"easyui-linkbutton l-btn\" iconcls=\"icon-cancel\" onclick=\"remove(this);\" id=\"\"><span class=\"l-btn-left\"><span class=\"l-btn-text\"><span class=\"l-btn-empty icon-cancel\">&nbsp;</span></span></span></a></td>"
				+ "</tr>";
		$("#filesupload").append(tr);
	}
	function remove(obj) {
		$(obj).parent().parent().remove();
	}
</script>
</html>
